from matplotlib import rc
rc('font',**{'family':'serif','serif':['Times']})
rc('text', usetex=True)

import numpy as np
import matplotlib.pyplot as plt
from pylab import *
from mpl_toolkits.axes_grid1 import make_axes_locatable, axes_size
import matplotlib.pyplot as pyplot

#Load data in each of the variables

x1, y1, den1, den2, den3, den4, den5, den6 = np.loadtxt('fig4.dat', unpack=True)




#
Nden1  = int(len(den1)**.5)
#
Nden2  = int(len(den2)**.5)
#
Nden3  = int(len(den3)**.5)
#
Nden4  = int(len(den4)**.5)
#
Nden5  = int(len(den5)**.5)
#
Nden6  = int(len(den6)**.5)



############################################################################
## Trasforming 1D data into a 2D matrix, and then rotate it by 90 degrees###
############################################################################

den1  = den1.reshape(Nden1, Nden1)
den1  = np.rot90(den1)
#   
########
den2  = den2.reshape(Nden2, Nden2)
den2  = np.rot90(den2)
########
den3  = den3.reshape(Nden3, Nden3)
den3  = np.rot90(den3)
########
den4  = den4.reshape(Nden4, Nden4)
den4  = np.rot90(den4)
########
den5  = den5.reshape(Nden5, Nden5)
den5  = np.rot90(den5)
########
den6  = den6.reshape(Nden6, Nden6)
den6  = np.rot90(den6)



cm = plt.cm.get_cmap('gnuplot2')

#############################################################################
## Positioning of subplots, and specifying the number of rows and columns ###
## in the resulting multiplot                                             ###
#############################################################################
fig1 = plt.figure(1)
fig1, axes = plt.subplots(nrows=3, ncols=2, figsize=(7.5,10))
plt.subplots_adjust(left=0.12, bottom=0.1, right=0.902, top=0.98,
                        wspace=0, hspace=0.05)
rc('axes', linewidth=1)
fontsize = 26
########################################
####   Figure (a)       ################
########################################
plt.subplot(3,2,1)
ax = plt.gca()
ax.text(41, 44,'(a)', fontsize=26, color='red', bbox={'facecolor':'white','alpha':0.9,'pad':2})


plt.xlim(-0.5, 49.5)
plt.ylim(-0.5, 49.5)
plt.yticks([-0.5,19.5,39.5],['$0$','$20$','$40$'],fontsize=26)
plt.xticks([-0.5,19.5,39.5],['','',''],fontsize=26)
plt.imshow(den1, extent=(np.amin(x1), np.amax(x1), np.amin(y1), np.amax(y1)),\
            vmin=0, vmax=1,cmap=cm, interpolation='none')

########################################
####   Figure (b)       ################
########################################
plt.subplot(3,2,3)
ax = plt.gca()
ax.text(41, 44,'(b)', fontsize=26, color='red', bbox={'facecolor':'white','alpha':0.9,'pad':2})
plt.minorticks_on()
plt.xlim(-0.5, 49.5)
plt.ylim(-0.5, 49.5)
plt.xticks([-0.5,19.5,39.5],['','',''],fontsize=26)
plt.yticks([-0.5,19.5,39.5],['$0$','$20$','$40$'],fontsize=26)
plt.imshow(den2, extent=(np.amin(x1), np.amax(x1), np.amin(y1), np.amax(y1)),\
          vmin=0, vmax=1, cmap=cm, interpolation='none')

########################################
####   Figure (c)       ################
########################################
plt.subplot(3,2,5)
ax = plt.gca()
ax.text(41, 44,'(c)', fontsize=26, color='red', bbox={'facecolor':'white','alpha':0.9,'pad':2})
plt.minorticks_on()
plt.xlim(-0.5, 49.5)
plt.ylim(-0.5, 49.5)
plt.xticks([-0.5,19.5,39.5],['$0$','$20$','$40$'],fontsize=26)
plt.yticks([-0.5,19.5,39.5],['$0$','$20$','$40$'],fontsize=26)
plt.imshow(den3, extent=(np.amin(x1), np.amax(x1), np.amin(y1), np.amax(y1)),\
            vmin=0, vmax=1,cmap=cm, interpolation='none')

########################################
####   Figure (d)       ################
########################################
plt.subplot(3,2,2)
ax = plt.gca()
ax.text(41, 44,'(d)', fontsize=26, color='red', bbox={'facecolor':'white','alpha':0.9,'pad':2})
plt.minorticks_on()
plt.xlim(-0.5, 49.5)
plt.ylim(-0.5, 49.5)
plt.xticks([-0.5,19.5,39.5],['','',''],fontsize=26)
plt.yticks([-0.5,19.5,39.5],['','',''],fontsize=26)
plt.imshow(den4, extent=(np.amin(x1), np.amax(x1), np.amin(y1), np.amax(y1)),\
            vmin=0, vmax=1,cmap=cm, interpolation='none')

########################################
####   Figure (e)       ################
########################################
plt.subplot(3,2,4)
ax = plt.gca()

ax.text(41, 44,'(e)', fontsize=26, color='red', bbox={'facecolor':'white','alpha':0.9,'pad':2})
plt.minorticks_on()
plt.xlim(-0.5, 49.5)
plt.ylim(-0.5, 49.5)
plt.yticks([-0.5,19.5,39.5],['','',''],fontsize=26)
plt.xticks([-0.5,19.5,39.5],['','',''],fontsize=26)

plt.imshow(den5, extent=(np.amin(x1), np.amax(x1), np.amin(y1), np.amax(y1)),\
            vmin=0, vmax=1,cmap=cm, interpolation='none')

########################################
####   Figure (f)       ################
########################################
plt.subplot(3,2,6)
ax = plt.gca()
ax.text(41, 44,'(f)', fontsize=26, color='red', bbox={'facecolor':'white','alpha':0.9,'pad':2})
plt.minorticks_on()
plt.xlim(-0.5, 49.5)
plt.ylim(-0.5, 49.5)
plt.xticks([-0.5,19.5,39.5],['$0$','$20$','$40$'],fontsize=26)
plt.yticks([-0.5,19.5,39.5],['','',''],fontsize=26)
plt.imshow(den6, extent=(np.amin(x1), np.amax(x1), np.amin(y1), np.amax(y1)),\
          vmin=0, vmax=1, cmap=cm, interpolation='none')

cbaxes = fig1.add_axes([0.93, 0.11, 0.02, 0.85])
cb = plt.colorbar(cax = cbaxes)
cb.ax.tick_params(labelsize=26)
cb.set_ticks([0,0.5,1])
cb.set_ticklabels(['0','','1'])

fig1.text(0.51, 0.03, r'$x$ (in units of $a$)',fontsize=26, ha='center', va='center')

fig1.text(0.03, 0.55, r'$y$ (in units of $a$)',fontsize=26, ha='center', va='center', rotation='vertical')

plt.show()
fig1.savefig('densityplot_lrd.pdf')

